package tech.dongliang.system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tech.dongliang.system.model.SysRoleMenu;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xdzhang
 * @since 2019-01-18
 */
public interface SysRoleMenuDao extends BaseMapper<SysRoleMenu> {
    @Select("SELECT menuId FROM sys_role_menu WHERE roleId = #{roleId} ")
    List<Integer> listMenuIdByRoleId(@Param("roleId") Integer roleId) throws Exception;

    @Select({
            "<script>",
            "SELECT menuId FROM sys_role_menu WHERE roleId in ",
            "<foreach collection='roleIds' item='roleId' index='index' open='(' close=')' separator=','>",
            "#{roleId}",
            "</foreach>",
            "</script>"
    })
    List<Integer> listMenuIdByRoleIds(@Param("roleIds") List<Integer> roleIds) throws Exception;

    @Delete("DELETE FROM sys_role_menu WHERE roleId = #{roleId} ")
    int removeByRoleId(@Param("roleId") Integer roleId) throws Exception;

    @Insert({
            "<script>",
            "insert into sys_role_menu(roleId, menuId) values ",
            "<foreach collection='menuIds' item='menuId' index='index' separator=','>",
            "(#{roleId}, #{menuId})",
            "</foreach>",
            "</script>"
    })
    int insertMenu(@Param("roleId") Integer roleId, @Param("menuIds") List<Integer> menuIds) throws Exception;
}
